#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_map>
#include <Vector.hpp>


using namespace std;

class Solution
{
public:
    vector<vector<string>> groupAnagrams(vector<string> &strs)
    {
        unordered_map<string, vector<string>> mp;
        for (auto str : strs)
        {
            string temp = str;
            sort(temp.begin(), temp.end());
            mp[temp].push_back(str);
        }
        vector<vector<string>> res;
        for (auto it = mp.begin(); it != mp.end(); it++)
        {
            res.push_back(it->second);
        }
        return res;
    }
};

int main()
{
    cout << "Code49" << endl;
    Solution s;
    vector<string> strs = {"eat", "tea", "tan", "ate", "nat", "bat"};
    vector<vector<string>> res = s.groupAnagrams(strs);
    Print2DVector(res);
    return 0;
}